<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//轮播banner图片
class Banner_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->table = 'banner';
    }
    
    function get($id){
        $this->db->select($this->table.'.*');
        $this->db->from($this->table);
        $this->db->where('id',$id);
        $query = $this->db->get();
        return $query->row_array(); 
    }
    
    function get_list($where,$page,$limit){
        $this->db->select($this->table.'.*');
        $this->db->from($this->table);
        $this->db->where($where);
        $this->db->order_by("create_time", "desc");
        $this->db->limit($limit, $page);
        $query = $this->db->get();
        return $query->result_array(); 
    }
    
    function get_count($where){
        $this->db->select('*');
        $this->db->from($this->table);
        $this->db->where($where);
        $this->db->order_by("create_time", "desc");
        $query = $this->db->get();
        return $query->num_rows();
    }
  
    
    //插入平台数据
    function insert($data)
    {
        $this->db->insert($this->table, $data);
        if($this->db->affected_rows()){
           return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    //更新平台数据
    function update($data,$table_id)
    {
            return $this->db->where('id',$table_id)->update($this->table, $data);
    }
    
    //删除数据
    function delete($delid)
    {	
            $this->db->where('id',$delid);
            $this->db->delete($this->table);
            return $this->db->affected_rows();
    }
}
